<div class="form-horizontal">
	<div class="form-group" id="userIdDiv">
		<label class="col-sm-2 control-label">邮箱/手机</label>
		<div class="col-sm-10">
            <input type="text" id="userName" name="userName" class="form-control"  maxlength="40" needvalicate="true" valicate="_required _emailOR_tel _minlen=6" placeholder="请填写您的有效邮箱/手机，以便找回密码以及验证" />
		</div>
	</div>
	<div class="form-group">
    	<label class="col-sm-2 control-label">验证码</label>
    	<div class="col-sm-7">
    		<input type="text" id="verifyCode" name="verifyCode" class="form-control" maxlength="6" needvalicate=true valicate="_required _num"  placeholder="请输入验证码"/>
    	</div>
    	<div class="col-sm-3">
    		<input type="button" id="svc" class="mybtn-primary m3" second="60" onclick="checkUserAndSendVerifyCode();" value="获取验证码"/>
    	</div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">密 码</label>
        <div class="col-sm-10">
            <input type="password" id="pwd" name="pwd" needvalicate="true" valicate="_required _minlen=6" class="form-control" placeholder="6-18位，可由数字字母特殊字符组成"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">重复密码</label>
        <div class="col-sm-10">
            <input type="password" id="pwd2" name="pwd2" needvalicate="true" valicate="_required _minlen=6 _equals=pwdForReg" class="form-control" placeholder="请填写重复密码"/>
        </div>
    </div>
    <div class="form-group">
		<div class="col-sm-12 text-center">
            <input onclick="canSubmit(this);" type="checkbox">
				<!-- <span class="p5">我已阅读并同意<a target="_blank" href="/DocSystem/pageTo.do?p=contactUs#useAgreement">《DocSys注册条款》</a></span> -->
				<span class="p5">我已阅读并同意<a>《DocSys注册条款》</a></span>
			</input>
       	</div>
	</div>
	<div class="form-group">
		<div class="col-sm-12 text-center">
			<input id="submitBtn" type="submit" class="hidden"/>
				<button  id="submit" type="button" class="btn btnPrimary" onclick="register();" style="width: 288px;height: 42px;" disabled>立即注册</button>
		</div>
	</div>
</div>
                    
<script src="js/md5.js"></script>
<script type="text/javascript">
	function RegisterPageInit()
	{
		//console.log($.cookie("dsuser"));
		//回车键监听函数
		EnterKeyListenerForRegister();
	}
	
	function closeRegister(){
		console.log("closeRegister");
		$("#registerdiv").remove();	//删除全屏遮罩
		$("#register").remove();	//删除对话框
	}
	
	//回车键监听函数
	function EnterKeyListenerForRegister(){
		var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异  
	 	if (event.keyCode == 13){  
	 		register();
	 	}  
	}
	
	//使能submit按键
	function canSubmit(dom){
		if(dom.checked) {
			$("#submit").attr('disabled',false);
		}
		else {
			$("#submit").attr('disabled',true);
		}
	}
	
	//登录按键处理函数
	function register(){
		console.log("register");
		
		//关闭按键点击避免连续点击
		$("#submit").attr('disabled',true);
		
        $.ajax({
            url : "/DocSystem/User/register.do",
            type : "post",
            dataType : "json",
            data : {
                 userName : $('input[name="userName"]').val(),
                 pwd : MD5($('input[name="pwd"]').val()),
                 pwd2: MD5($('input[name="pwd2"]').val()),
                 verifyCode : $('input[name="verifyCode"]').val(),
            },
            success : function (ret) {
            	$("#submit").attr('disabled',false);
                if( "ok" == ret.status ){
                	//window.location.href = "index.html";	//跳转到主页

                	loginUser =  $('input[name="userName"]').val();
                	
                	//关闭注册对话框
                	closeRegister();
                	//弹出登录对话框
                	showLoginPanel();
                }else {
                	showErrorMessage("错误：" + ret.msgInfo);
                }
            },
            error : function () {
            	$("#submit").attr('disabled',false);
            	showErrorMessage("服务器异常:注册失败");
            }
        });
    }
	
	//检查用户是否注册并发送验证码
	function checkUserAndSendVerifyCode(){
		console.log("checkUserAndSendVerifyCode");
		
		$.ajax({
            url : "/DocSystem/User/checkUserRegistered.do",
            type : "post",
            dataType : "json",
            data : {
                 userName : $('input[name="userName"]').val(),
            },
            success : function (ret) {
                if( "ok" == ret.status ){
                	//showErrorMessage("用户不存在，可以注册");
                	sendVerifyCode();
                }else {
                	showErrorMessage("错误：" + ret.msgInfo);
                }
            },
            error : function () {
            	showErrorMessage("服务器异常:发送验证码失败");
            }
        });
        
	}
	
	//发送验证码
	function sendVerifyCode()
	{
		var dom = $("#svc");
		
		$(dom).attr("disabled","disabled");
		$(dom).attr("second","60");
		remainTime(dom);
			
		$.ajax({
            url : "/DocSystem/User/sendVerifyCode.do",
            type : "post",
            dataType : "json",
            data : {
                 userName : $('input[name="userName"]').val(),
            },
            success : function (ret) {
                if( "ok" == ret.status ){
                	showErrorMessage("验证码已发送，请注意查收！");
                }else {
                	showErrorMessage("错误：" + ret.msgInfo);
                }
            },
            error : function () {
            	showErrorMessage("服务器异常:发送验证码失败");
            }
        });
	}
	
	//验证码倒计时
	function remainTime(){
		var dom = $("#svc");
		var i = $(dom).attr("second");
		$(dom).val(--i + "s"); 
		$(dom).attr("second",i);
	    var t = setTimeout(remainTime,1000);
	    if(i==0){
	    	clearTimeout(t);
	    	$(dom).removeAttr("disabled");
	    	$(dom).val("获取验证码");
	    }
	} 
	
	//页面初始化代码    
    $(function(){
    	console.log("register Page init");
		RegisterPageInit();
		$("#userName").click().focus();
	});
</script>